package com.lagou.controller;

import com.lagou.domain.Employee;
import com.lagou.domain.QueryVo;
import com.lagou.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.Date;

/**
 * @author Roger
 * @date 2020/8/20 10:31
 * @description
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/quick")
    public String quick() {
        return "success";
    }

    @RequestMapping("/simpleParam")
    public String simplaeParam(String username, Integer id) {
        System.out.println(username);
        System.out.println(id);
        return "success";
    }

    @RequestMapping("/pojoParam")
    public String pojoParam(User user) {
        System.out.println(user);
        return "success";
    }

    @RequestMapping("/arrayParam")
    public String arrayParam(Integer[] ids) {
        System.out.println(Arrays.toString(ids));
        return "success";
    }

    @RequestMapping("/queryParam")
    public String queryParam(QueryVo queryVo) {
        System.out.println(queryVo);
        return "success";
    }

    @RequestMapping("/converterParam")
    public String converterParam(Date birthday) {
        System.out.println(birthday);
        return "success";
    }


    /*
        @RequestBody：当前端使用ajax请求并且 contentType为json的时候 需要使用这个注解来获取参数
        @ResponseBody：需要把数据以json格式传给前端时 需要使用这个注解
    */
    @RequestMapping(value = "/ajaxRequest",method = RequestMethod.POST)
    @ResponseBody
    public Employee ajaxRequest(@RequestBody Employee user) {
        System.out.println(user);

        return user;
    }

    @RequestMapping("/interceptor")
    public String interceptor() {
        System.out.println("执行了...");
        return "success";

    }



}
